import java.util.Arrays;

public class Solution1710 {
    public int maximumUnits(int[][] boxTypes, int truckSize) {
        Arrays.sort(boxTypes,(a,b)->b[1]-a[1]);
        int ans=0;
        for (int[] boxType : boxTypes) {
            int t=Math.min(truckSize,boxType[0]);
            ans+=t*boxType[1];
            truckSize-=t;
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new Solution1710().maximumUnits(new int[][]{{1,3},{2,2},{3,1}},4));
    }
}
